package 第3节函数;

import java.util.Arrays;

//全排列问题
public class RecursionDemo04 {
    public static void main(String[] args) {
        int[] arr = new int[3];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i + 1;
        }
        permutation(arr,0, arr.length - 1);
    }
    public static void permutation(int[] arr, int from, int to) {
        if (from == to) {
            System.out.println(Arrays.toString(arr));
        } else {
            for (int i = from; i <= to; i++) {
                swap(arr,i, from);
                permutation(arr, from + 1, to);
                swap(arr, i, from);
            }
        }
    }
    private static void swap(int[] arr, int i, int from) {
        int temp = arr[i];
        arr[i] = arr[from];
        arr[from] = temp;
    }
}
